package org.hxzon.hdyn;

import java.util.Map;

public class HObject {

    protected HGlobal global;
    protected String parent;
    protected Map<String, Object> fields;
    protected Map<String, HFun> funs;

    public HObject(HGlobal global) {
        this.global = global;
    }

    public HObject(String parent, Map<String, Object> fields) {
        this.parent = parent;
        this.fields = fields;
    }

    public Object field(String name) {
        Object r = fields.get(name);
        if (r == null && parent != null) {
            HObject ko = global.hvar(parent);
            if (ko != null) {
                r = ko.field(name);
            }
        }
        return r;
    }

    public HFun funs(String name) {
        HFun r = funs.get(name);
        if (r == null && parent != null) {
            HObject ko = global.hvar(parent);
            if (ko != null) {
                r = ko.funs(name);
            }
        }
        return r;
    }
}
